//
//  PostViewController.m
//  parent
//
//  Created by 闫珍 on 15/5/28.
//  Copyright (c) 2015年 ci123. All rights reserved.
//

#import "PostViewController.h"
#import "PopUIManager.h"
#import "MBProgressHUD.h"
#import "AFAppClient.h"
#import "AFNetworking.h"
#import "UserDao.h"
#import "NetWorkManager.h"
#import "AFAppClient.h"
#import "Config.h"

typedef NS_ENUM(NSInteger,  UIMarkTag) {
    UISortLabelTag = 501,
    UISortTopBorderTag,
    UIKeyboardTag,
    UIPicTag,
    UIPicNumTag,
    UIPicViewTag
};

#define CacheName               @"postCategory"
#define EmojiViewHeight         ((Current_device_vesion < 7.0) ? 165 : 145)
#define MaximumNumberOfPhotos   9

@interface PostViewController ()
@property (nonatomic,retain)MBProgressHUD *hud;
@end

@implementation PostViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        _keyboardHeight = 216;
        _inputType = 1;
        _isKeyboardShow = YES;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    
    self.view.backgroundColor = DefaultViewBackgroundColor;
    [self _initView];
    [self _initBlocks];
    // Do any additional setup after loading the view from its nib.
    [self customView];
    
}
-(void)customView
{
    self.navigationController.navigationBarHidden = NO;
    
    if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
        self.edgesForExtendedLayout = UIRectEdgeNone;
    
    self.navigationItem.title = @"发帖";
    
//    UIBarButtonItem *leftItem =[[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(leftClick:)];
    UIBarButtonItem *leftItem =[[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"窗口"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(leftClick:)];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    UIBarButtonItem *rightItem =[[UIBarButtonItem alloc]initWithTitle:@"发送" style:UIBarButtonItemStylePlain target:self action:@selector(pubAction:)];
    self.navigationItem.rightBarButtonItem = rightItem;
}
-(void)leftClick:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}



- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [NOTIFICATION_CENTER addObserver:self
                            selector:@selector(keyboardWillShow2:)
                                name:UIKeyboardWillShowNotification
                              object:nil];
    [NOTIFICATION_CENTER addObserver:self
                            selector:@selector(keyboardWillHide2:)
                                name:UIKeyboardWillHideNotification
                              object:nil];
    
    [_pubView performSelector:@selector(titleBecomeResign) withObject:nil afterDelay:0.8];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    [NOTIFICATION_CENTER removeObserver:self
                                   name:UIKeyboardWillShowNotification
                                 object:nil];
    [NOTIFICATION_CENTER removeObserver:self
                                   name:UIKeyboardWillHideNotification
                                 object:nil];
}

#pragma mark - MBHud
- (void)showHud:(NSString *)title isDim:(BOOL)isDim {
    _hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    _hud.dimBackground = isDim;
    if(title.length > 0) {
        _hud.labelText = title;
    }
}

- (void)showHudComplete:(NSString *)title success:(BOOL)success {
    NSString *name = success ? @"success" : @"excla";
    _hud.dimBackground = NO;
    _hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:name]];
    _hud.mode = MBProgressHUDModeCustomView;
    if(title.length > 0) {
        _hud.labelText = title;
    }
    [_hud hide:YES afterDelay:1];
}

- (void)ShowExclaHud:(NSString *)title{
    _hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [self showHudComplete:title success:NO];
}

- (void)hideHud {
    [_hud hide:YES];
}
#pragma mark - Action
- (void)pubAction:(id )button {
    UIBarButtonItem *right = (UIBarButtonItem*)button;
    right.enabled =NO;
    [self changeKeyBoard:nil];
    if(![_pubView checkAllContent]) {
        right.enabled = YES;
        return;
    }
    [self showHud:@"发送中" isDim:YES];
    
    NSString *content = [_pubView getContents];
    
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:@{
                                                                                  @"title":[_pubView getTitles],
                                                                                  @"content":content,
                                                                                  @"uid":@([[Config Instance]getUID]),
                                                                                  @"utype":@(1),
                                                                                  @"posttype":_postType,
                                                                                  @"message":USER_POST_ARTICLE
                                                                                  }];
    if([_picImages count] > 0) {
        for (int i=0; i<[_picImages count]; i++) {
            [params setObject:_picImages[i] forKey:[NSString stringWithFormat:@"image%d.jpg",i]];
        }
    }
    [[AFAppClient sharedManager] postWithURL:[NSString stringWithFormat:@"%@%@",SERVER_URL_NEW,API_USER_POST_ARTICLE] withParameters:params success:self.blockPubPostSuccess failure:nil];
    right.enabled = YES;
}//发表
/*
- (void)showSortView {
    UIImageView *arrowView = (UIImageView *)[_titleView viewWithTag:UISortTopBorderTag];
    if(_sortBackgroudView.hidden == YES) {
        [_sortBackgroudView setHidden:NO];
        [UIView animateWithDuration:0.3f
                              delay:0
                            options:UIViewAnimationOptionCurveEaseInOut
                         animations:^(void){
                             arrowView.transform = CGAffineTransformMakeRotation(180 * M_PI / 180.0);
                         }
                         completion:nil];
        self.navigationController.navigationBar.clipsToBounds = YES;
    }else {
        [_sortBackgroudView setHidden:YES];
        [UIView animateWithDuration:0.3f
                              delay:0
                            options:UIViewAnimationOptionCurveEaseInOut
                         animations:^(void){
                             arrowView.transform = CGAffineTransformMakeRotation(0.0);
                         }
                         completion:nil];
        self.navigationController.navigationBar.clipsToBounds = NO;
        //改变分类标题
        [self changeTitleLabel];
    }
}//点击分类选择动画
 */

- (void)addPic:(UIButton *)button {
    if([_picImages count] >= MaximumNumberOfPhotos) {
        [self changeKeyBoard:nil];
        [self ShowExclaHud:[NSString stringWithFormat:@"最多上传%d张图片", MaximumNumberOfPhotos]];
        return;
    }
    
    UIActionSheet *menu = [[UIActionSheet alloc]
                           initWithTitle: @""
                           delegate:self
                           cancelButtonTitle:@"取消"
                           destructiveButtonTitle:nil
                           otherButtonTitles:@"拍照",@"图库相册", nil];
    [menu showInView:self.view];
}//添加图片

- (void)changeKeyBoard:(UIButton *)button {
    UIButton *keyboard = (UIButton *)[_floatingView viewWithTag:UIKeyboardTag];
    if(_isKeyboardShow) {
        [keyboard setImage:[UIImage imageNamed:@"pub_btn_keyboard_up"] forState:UIControlStateNormal];
        [_pubView hideKeyboard];
        [UIView animateWithDuration:0.23 animations:^{
            _floatingView.bottom = APP_SCREEN_HEIGHT - 64;
            
        }];
        _isKeyboardShow = NO;
    }else {
        if (_inputType == 1) {
            [_pubView.title becomeFirstResponder];
        }else {
            [_pubView.content becomeFirstResponder];
        }
        [keyboard setImage:[UIImage imageNamed:@"pub_btn_keyboard_down"] forState:UIControlStateNormal];
        [UIView animateWithDuration:0.23
                         animations:^{
                             _floatingView.bottom = APP_SCREEN_HEIGHT - 64 -_keyboardHeight;
                         }
                         completion:^(BOOL finish){}];
        _isKeyboardShow = YES;
    }
    
}//切换键盘

- (void)managePics:(UITapGestureRecognizer *)tap {
    [self ShowOrHidePic:NO];
    if(_browser == nil) {
        _browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
        _browser.displayActionButton = YES;
        _browser.displayNavArrows = YES;
        _browser.enableGrid = NO;
    }
    
    UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:_browser];
    nc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentViewController:nc animated:YES completion:nil];
    [_browser setCurrentPhotoIndex:[_picImages count] - 1];
}//管理图片

- (void)backPage:(id)button{
    [self changeKeyBoard:nil];
    [self.navigationController popViewControllerAnimated:YES];
}



#pragma mark UIScrollViewDelegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    
}

#pragma mark - NOTIFICATION_CENTER
- (void)keyboardWillShow2:(NSNotification *)notification
{
    NSValue *keyboardValue = [notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect frame = [keyboardValue CGRectValue];
    _keyboardHeight = frame.size.height;
    
    UIButton *keyboard = (UIButton *)[_floatingView viewWithTag:UIKeyboardTag];
    [keyboard setImage:[UIImage imageNamed:@"pub_btn_keyboard_down"] forState:UIControlStateNormal];
    [UIView animateWithDuration:0.23
                     animations:^{
                         _floatingView.bottom = APP_SCREEN_HEIGHT-64 - _keyboardHeight;
                         _pubView.height = _floatingView.bottom-_floatingView.height;
                         _pubView.content.height = _pubView.height-40;
                         _pubView.content.contentSize = _pubView.content.size;
                     }
                     completion:^(BOOL finish){
                         _isKeyboardShow = YES;
                     }];
}

- (void)keyboardWillHide2:(NSNotification *)notification
{
    [self changeKeyBoard:nil];
    UIButton *keyboard = (UIButton *)[_floatingView viewWithTag:UIKeyboardTag];
    [keyboard setImage:[UIImage imageNamed:@"pub_btn_keyboard_up"] forState:UIControlStateNormal];
    _isKeyboardShow = NO;
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    _inputType = 1;
      return YES;
}

//保存标题
- (void)textFieldDidEndEditing:(UITextField *)textField{
    NSString *title=_pubView.getTitles;
    [USER_DEFAULT setObject:title forKey:UDPostTitleIdentify];
    [USER_DEFAULT synchronize];
}

//保存帖子内容
- (void)textViewDidChange:(UITextView *)textView{
    NSString *content=_pubView.getContents;
    [USER_DEFAULT setObject:content forKey:UDPostContentIdentify];
    [USER_DEFAULT synchronize];
}

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    _inputType = 2;
    if([textView isEqual:_pubView.content]&&[_pubView.getContents isEqualToString:@"内容"]){
        _pubView.contentPlaceHolder=@"";
        _pubView.content.textColor=UIColorMake(0, 0, 0);
    }
    return YES;
}

#pragma mark - UI
- (void)_initView
{
    _pubView = [[BasePubView alloc] initWithFrame:CGRectMake(0, 0, APP_SCREEN_WIDTH, APP_SCREEN_HEIGHT-44-20-40-216)];
    _pubView.changeGap = APP_SCREEN_HEIGHT-20-44-40-216-40+20;
    _pubView.backgroundColor = [UIColor whiteColor];
    _pubView.contentPlaceHolder = @"内容";
    
    if(_titleText) {
        _pubView.titleText = [NSString stringWithFormat:@"%@",_titleText];
    }
    
    if([UDPostTitle length]>3 && [UDPostContent length]>10){
        _pubView.titleText=[NSString stringWithFormat:@"%@",UDPostTitle];
        _pubView.content.text=[NSString stringWithFormat:@"%@",UDPostContent];
        _pubView.content.textColor=UIColorMake(0, 0, 0);
    
    }
    
    _pubView.title.delegate=self;
    _pubView.content.delegate=self;
    
    [self.view addSubview:_pubView];

    
    //浮动栏
    [self _initFloatingView];
    
   // [self.view bringSubviewToFront:_sortBackgroudView];
}


- (void)_initFloatingView {
    _floatingView = [[UIView alloc] initWithFrame:CGRectMake(0, _pubView.bottom, APP_SCREEN_WIDTH, 40)];
    _floatingView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_floatingView];
    
    
    UIButton *camera = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 54, 40)];
    camera.backgroundColor = [UIColor clearColor];
    [camera setImage:[UIImage imageNamed:@"camara_little"] forState:UIControlStateNormal];
    [camera addTarget:self action:@selector(addPic:) forControlEvents:UIControlEventTouchUpInside];
    [_floatingView addSubview:camera];
    
    UIButton *keyboard = [[UIButton alloc] initWithFrame:CGRectMake(camera.right, 0, 54, 40)];
    keyboard.backgroundColor = [UIColor clearColor];
    keyboard.tag = UIKeyboardTag;
    [keyboard setImage:[UIImage imageNamed:@"pub_btn_keyboard_down"] forState:UIControlStateNormal];
    [keyboard addTarget:self action:@selector(changeKeyBoard:) forControlEvents:UIControlEventTouchUpInside];
    [_floatingView addSubview:keyboard];
    
    //左侧图片
    UIImageView *pics = [[UIImageView alloc] initWithFrame:CGRectMake(-35, 4, 35, 35)];//x:8
    pics.image = [UIImage imageNamed:@"pic_border"];
    pics.backgroundColor = [UIColor clearColor];
    pics.userInteractionEnabled = YES;
    pics.tag = UIPicViewTag;
    [_floatingView addSubview:pics];
    [pics setHidden:YES];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(managePics:)];
    [pics addGestureRecognizer:tap];
    
    UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(4, 4, 27, 27)];
    img.backgroundColor = [UIColor clearColor];
    img.tag = UIPicTag;
    img.image = [UIImage imageNamed:@"head"];
    [pics addSubview:img];
    
    UILabel *num = [[UILabel alloc] initWithFrame:CGRectMake(-4, -4, 17, 17)];
    num.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"warn"]];
    num.textColor = [UIColor whiteColor];
    num.tag = UIPicNumTag;
    num.textAlignment = NSTextAlignmentCenter;
    num.font = [UIFont systemFontOfSize:12];
    num.text = @"0";
    [pics addSubview:num];
}

#pragma mark - Private Method
- (void)changeTitleLabel {
    UILabel *titltText = (UILabel *)[_titleView viewWithTag:UISortLabelTag];
    NSInteger index = [_sortView.indexPathForSelectedRow row];
    titltText.text = [NSString stringWithFormat:@"%@",[_postCategory allValues][index]];
}//改变分类标题


- (void)openGallery:(UIImagePickerControllerSourceType) source{
    //初始化类
    UIImagePickerController *pick = [[UIImagePickerController alloc] init];
    //指定图片来源
    pick.sourceType = source;
    //表示用户可编辑图片。
    pick.allowsEditing = NO;
    //代理
    pick.delegate = self;
    [self presentViewController:pick animated:YES completion:nil];
}//打开相册或者相机

- (void)ShowOrHidePic:(BOOL)show {
    UIImageView *view = (UIImageView *)[_floatingView viewWithTag:UIPicViewTag];
    if(show) {
        view.hidden = NO;
        if([_picImages count] > 0){
            UIImageView *pic = (UIImageView *)[_floatingView viewWithTag:UIPicTag];
            pic.image = _picImages[[_picImages count] - 1];
            
            UILabel *num = (UILabel *)[_floatingView viewWithTag:UIPicNumTag];
            num.text = [NSString stringWithFormat:@"%ld",[_picImages count]];
            [UIView animateWithDuration:0.5 animations:^{
                view.left = 8;
            }];
        }
    }else {
        [UIView animateWithDuration:0.5 animations:^{
            view.left = 8;
        }];
    }
}//显示或者隐藏左侧图片

#pragma mark - MWPhotoBrowserDelegate
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
    return [_picImages count];
}

- (MWPhoto *)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
    if (index < _picImages.count) {
        return [MWPhoto photoWithImage:_picImages[index]];
    }
    return nil;
}

- (BOOL)photoBrowser:(MWPhotoBrowser *)photoBrowser deletePhotoAtIndex:(NSUInteger)index
{
    [_picImages removeObjectAtIndex:index];
    if([_picImages count] == 0) {
        [_browser reloadData];
        [self dismissViewControllerAnimated:YES completion:nil];
        UIImageView *view = (UIImageView *)[_floatingView viewWithTag:UIPicViewTag];
        [view setHidden:YES];
        return NO;
    }else {
        [_browser reloadData];
        if(index+1 < [_picImages count]) {
            [_browser setCurrentPhotoIndex:index + 1];
        }else {
            [_browser setCurrentPhotoIndex:index - 1];
        }
        return YES;
    }
    return NO;
}

- (void)deletePicFromBrower
{
    NSInteger i = _browser.currentIndex;
    [_picImages removeObjectAtIndex:i];
    if([_picImages count] == 0) {
        [_browser reloadData];
        [self dismissViewControllerAnimated:YES completion:nil];
        UIImageView *view = (UIImageView *)[_floatingView viewWithTag:UIPicViewTag];
        [view setHidden:YES];
    }else {
        [_browser reloadData];
        if(i+1 < [_picImages count]) {
            [_browser setCurrentPhotoIndex:i + 1];
        }else {
            [_browser setCurrentPhotoIndex:i - 1];
        }
    }
}

- (void)photoBrowserDidFinishModalPresentation:(MWPhotoBrowser *)photoBrowser
{
    [self ShowOrHidePic:YES];
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (BOOL)checkCamera {
    BOOL isCamera = [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];
    if(!isCamera) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"此设备没有摄像头" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return NO;
    }else{
        return YES;
    }
}
#pragma mark - UIActionSheetDelegate

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    UIImagePickerControllerSourceType sourceType;
    if(buttonIndex==0) {
        if([self checkCamera]){
            sourceType = UIImagePickerControllerSourceTypeCamera;
            [self openGallery:sourceType];
        }else{
            return;
        }
    }else if(buttonIndex == 1){
        //sourceType= UIImagePickerControllerSourceTypePhotoLibrary;
        //[self openGallery:sourceType];
        UzysAssetsPickerController *picker = [[UzysAssetsPickerController alloc] init];
        picker.delegate = self;
        picker.maximumNumberOfSelectionVideo = 0;
        picker.maximumNumberOfSelectionPhoto = MaximumNumberOfPhotos;
        //        if (_picImages.count > 0) {
        //            picker.defaultSelectedAssets = _picImages;
        //        }
        [self presentViewController:picker animated:YES completion:nil];
    }else {
        [self ShowOrHidePic:YES];
    }
}

#pragma mark - UzysAssetsPickerControllerDelegate

- (void)uzysAssetsPickerController:(UzysAssetsPickerController *)picker didFinishPickingAssets:(NSArray *) assets
{
    if(assets.count <= 0) {
        return;
    }
    
    if([[assets[0] valueForProperty:@"ALAssetPropertyType"] isEqualToString:@"ALAssetTypePhoto"]) //Photo
    {
        if(_picImages == nil) {
            _picImages = [[NSMutableArray alloc] initWithCapacity:1];
        }else {
            [_picImages removeAllObjects];
        }
        __weak typeof(self) weakSelf = self;
        [assets enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
            ALAsset *representation = obj;
            UIImage *image = [UIImage imageWithCGImage:representation.defaultRepresentation.fullResolutionImage
                                                 scale:representation.defaultRepresentation.scale
                                           orientation:UIImageOrientationUp];
            [weakSelf.picImages addObject:image];
            
            if (idx >= assets.count - 1) {
                *stop = YES;
                [weakSelf.browser reloadData];
                [weakSelf ShowOrHidePic:YES];
            }
        }];
    }
}

#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController: (UIImagePickerController *)picker
didFinishPickingMediaWithInfo: (NSDictionary *)info {
    UIImage *image = [info objectForKey: @"UIImagePickerControllerOriginalImage"];
    
    if (image.imageOrientation != UIImageOrientationUp){
        UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);
        [image drawInRect:(CGRect){0, 0, image.size}];
        UIImage *normalizedImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        image=normalizedImage;
    }
    
    if(_picImages == nil) {
        _picImages = [[NSMutableArray alloc] initWithCapacity:1];
    }
    [_picImages addObject:image];
    [_browser reloadData];
    
    [picker dismissViewControllerAnimated:YES completion:nil];
    [self ShowOrHidePic:YES];
}

- (void)imagePickerControllerDidCancel: (UIImagePickerController *)picker {
    [self dismissViewControllerAnimated:YES completion:nil];
    //显示图片
    [self ShowOrHidePic:YES];
}

#pragma mark - AFNetworking Block

- (void)_initBlocks
{
    __weak typeof (self) weakSelf = self;
    
    self.blockGetSortSuccess = ^(NSDictionary *response){
        __strong typeof (self) strongSelf = weakSelf;
        if (!strongSelf) {
            return;
        }
        
        if([response[@"ret"] isEqualToNumber:@1]) {
            NSString *path = [HomeDirectory stringByAppendingString:[NSString stringWithFormat:@"%@.plist",CacheName]];
            [response[@"data"] writeToFile:path atomically:YES];
        }
    };
    
    self.blockPubPostSuccess = ^(NSDictionary *response){
        __strong typeof (self) strongSelf = weakSelf;
        if (!strongSelf) {
            return;
        }
        
        if([response[@"ret"] isEqualToNumber:@1]) {
            [strongSelf showHudComplete:@"发表成功" success:YES];
            
            [USER_DEFAULT setObject:@"" forKey:UDPostContentIdentify];
            [USER_DEFAULT setObject:@"" forKey:UDPostTitleIdentify];
                       [USER_DEFAULT synchronize];
            /*
            DetailNewViewController *detailViewController = [[DetailNewViewController alloc] init];
            if (response && response[@"data"] && response[@"data"][@"id"]) {
                detailViewController.pid = response[@"data"][@"id"];
            }else {
                detailViewController.pid = @"0";
            }
            detailViewController.isPost = YES;
            detailViewController.isPost = YES;
            [detailViewController setHidesBottomBarWhenPushed:YES];
             
            [strongSelf.navigationController pushViewController:detailViewController animated:YES];*/
            [strongSelf dismissViewControllerAnimated:YES completion:^{
                
            }];
        }else {
            [strongSelf showHudComplete:@"发表失败" success:NO];
            strongSelf.navigationController.navigationItem.rightBarButtonItem.enabled = YES;
        }
    };
}

#pragma mark - UITableViewDataSource
/*
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [_postCategory count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                      reuseIdentifier: CellIdentifier];
        cell.backgroundColor = [UIColor clearColor];
        cell.contentView.backgroundColor = [UIColor clearColor];
        cell.textLabel.backgroundColor = [UIColor clearColor];
        cell.textLabel.textAlignment = NSTextAlignmentCenter;
        cell.textLabel.textColor = UIColorMake(135, 135, 135);
        cell.textLabel.highlightedTextColor = UIColorMake(255, 83, 123);
        cell.textLabel.font = [UIFont systemFontOfSize:18.0f];
        UIImageView *selectedBg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sort_selected_bg"]];
        cell.selectedBackgroundView = selectedBg;
    }
    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.textLabel.textAlignment = NSTextAlignmentCenter;
    cell.textLabel.textColor = UIColorMake(135, 135, 135);
    
    cell.textLabel.text = [_postCategory allValues][indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self showSortView];
}
*/
#pragma mark - Memory
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end